package org.glut.wechat.addresslist.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.glut.wechat.addresslist.entity.Request;
import org.glut.wechat.addresslist.vo.RequestVO;

import java.util.List;

/**
* 申请添加好友表 Mapper
*
* @author harry
* @since 2025-08-21 20:25
*/
@Mapper
public interface RequestMapper extends BaseMapper<Request> {
    // 关联查询：申请信息和申请人信息user表
    @Select("""
        SELECT r.*, u.username, u.avatar 
        FROM request r 
        LEFT JOIN user u ON r.from_user_id = u.id 
        WHERE r.to_user_id = #{toUserId} AND r.status = 0
        """)
    List<RequestVO> getNewRequests(@Param("toUserId") Integer toUserId);
}
